package org.biliviz.be.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.biliviz.be.entity.AuthorData;
import org.biliviz.be.entity.AuthorInfo;
import org.biliviz.be.entity.vo.AuthorDataVo;
import org.biliviz.be.mapper.AuthorDataMapper;
import org.biliviz.be.service.AuthorDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.lang.reflect.Type;
import java.util.Comparator;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sg
 * @since 2024-03-02
 */
@Service
public class AuthorDataServiceImpl extends ServiceImpl<AuthorDataMapper, AuthorData> implements AuthorDataService {

    @Override
    public List<AuthorData> getAll() {
        List<AuthorData> AuthorData = baseMapper.selectList(null);
        return AuthorData;
    }

    @Override
    public List<AuthorDataVo> getAuthorData(Long mid) {
        QueryWrapper<AuthorData> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mid", mid);
        AuthorData author = baseMapper.selectOne(queryWrapper);
        Gson gson = new Gson();
        String jsonData = author.getData(); // 假设 author.getData() 方法获取到了 JSON 数据
        Type authorDataListType = new TypeToken<List<AuthorDataVo>>(){}.getType();
        List<AuthorDataVo> authorDataList = gson.fromJson(jsonData, authorDataListType);
        return authorDataList;
    }
}
